package com.meizhitech.mzcmsapi.utils;

import cloud.tianai.captcha.common.constant.CaptchaTypeConstant;
import cloud.tianai.captcha.common.response.ApiResponse;
import cloud.tianai.captcha.spring.application.CaptchaImageType;
import cloud.tianai.captcha.spring.application.ImageCaptchaApplication;
import cloud.tianai.captcha.spring.vo.CaptchaResponse;
import cloud.tianai.captcha.spring.vo.ImageCaptchaVO;
import cloud.tianai.captcha.validator.common.model.dto.ImageCaptchaTrack;
import com.meizhitech.mzcmsapi.api.param.CaptchaParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collections;

@Component
public class CaptchaUtil {
    @Autowired
    private ImageCaptchaApplication imageCaptchaApplication;

    public CaptchaResponse<ImageCaptchaVO> createCaptcha() {
        CaptchaResponse<ImageCaptchaVO> res1 = imageCaptchaApplication.generateCaptcha();
        return res1;
    }

    public ApiResponse<?> checkCaptcha(CaptchaParam captchaParam){
        ApiResponse<?> match = imageCaptchaApplication.matching(captchaParam.getId(), captchaParam.getData());
        if (match.isSuccess()) {
            return ApiResponse.ofSuccess(Collections.singletonMap("id", captchaParam.getId()));
        }
        return  match;
    }
}
